package com.qf.medical.utils;

import com.alibaba.fastjson.JSONObject;
import com.qiniu.util.Auth;
import com.qiniu.util.StringMap;


public class QiNiuUtils {
   private static final String accessKey = "1yXETXxQKE57kIjXJHwdrmeLk-G-j2_IBtUx0NmO";
   private static final String secretKey = "1yXETXxQKE57kIjXJHwdrmeLk-G-j2_IBtUx0NmO";


    /**
     * 获取文件上传使用的token
     * 并且设置返回类型为json
     * @param bucket 储存捅的名称 agreeable
     * @return 返回String类型的token
     */
    public static String getToken(String bucket){
        Auth auth = Auth.create(accessKey, secretKey);
        StringMap putPolicy = new StringMap();
        JSONObject resultJsonTemplate = new JSONObject().fluentPut("key", "http://ru7tgjp8e.hb-bkt.clouddn.com/$(key)").fluentPut("hash", "$(etag)").fluentPut("bucket", "$(fsize)");
        putPolicy.put("returnBody", resultJsonTemplate.toJSONString());
        long expireSeconds = 3600;

        return auth.uploadToken(bucket, null, expireSeconds, putPolicy);
    }




}
